﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddContractCtrl.ascx.cs"
    Inherits="WebUI.Controls.AddContractCtrl" %>
<script type="text/javascript">
    var <%=ClientID %>clickOnCheckbox;
    var <%=ClientID %>selectedRow = null;       
    var <%=ClientID %>selectedCheckbox = null; 
    var <%=ClientID %>selectedID = null; 
    var <%=ClientID %>selectedClass = null; 

    function resetGridSelection<%=ClientID %>(){
        <%=ClientID %>selectedRow = null;   
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;          
        <%=ClientID %>selectedCheckbox = null; 
        <%=ClientID %>selectedID = null; 
        <%=ClientID %>selectedClass = null; 
    }

    function clickOnCheckBox<%=ClientID %>(cb){
        <%=ClientID %>clickOnCheckbox = true;
    }

    function onItemClick<%=ClientID %>(sender){
        var hidSelectedID = document.getElementById("<%= hidSelectedID.ClientID %>");
        if(<%=ClientID %>clickOnCheckbox){
            <%=ClientID %>clickOnCheckbox = false;
            return;
        }

        if(<%=ClientID %>selectedRow == null){
            <%=ClientID %>selectedRow = document.getElementById("<%=ClientID %>" + "_row_" + hidSelectedID.value);
        }
        
        if(<%=ClientID %>selectedRow != null){
            if(<%=ClientID %>selectedRow.className)
                <%=ClientID %>selectedRow.className = <%=ClientID %>selectedRow.getAttribute("orgclass");
            else
                <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;
            else{
                var chks = <%=ClientID %>selectedRow.getElementsByTagName("input");
                 for(var i = 0; i < chks.length; i++){
                    if(chks[i].type == "checkbox" && chks[i].id.indexOf("cbSelect") >= 0){
                        chks[i].checked = false;
                        break;
                    }
                }
            }
        }
        
        if(sender.className){
            sender.className = "CustomGridSelectedItem";
        }
        else{
            <%=ClientID %>selectedClass = sender.getAttribute("class");
            sender.setAttribute("class", "CustomGridSelectedItem");
        }
        <%=ClientID %>selectedRow = sender;
        
        var inputs = sender.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
                <%=ClientID %>selectedCheckbox = inputs[i];
                inputs[i].checked = true;
                break;
            }
        }

        hidSelectedID.value = <%=ClientID %>selectedRow.getAttribute("ItemID");
    }

    function selectAll<%=ClientID %>(cbAll){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"){
                inputs[i].checked = cbAll.checked;
            }
    }
}

    function getSelectedItemID<%=ClientID %>(){
        if(document.getElementById("<%= hidSelectedID.ClientID %>").value == "")
            return null;
        return document.getElementById("<%= hidSelectedID.ClientID %>").value;
    }
</script>
<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None"
    class="customGrid" AutoGenerateColumns="false" EmptyDataText="No record to display"
    ItemStyle-Wrap="true" CellPadding="1" CellSpacing="1" OnSortCommand="grid_OnSortCommand"
    OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound" OnPageIndexChanged="grid_OnPageIndexChanged"
    AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
    <PagerStyle Mode="NumericPages" PageButtonCount="10" />
    <Columns>
        <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center"
            HeaderStyle-HorizontalAlign="Center">
            <HeaderTemplate>
                <asp:CheckBox ID="cbSelectAll" runat="server" /></HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="150px" DataField="ID" SortExpression="ID" HeaderText="ID" Visible="false">
        </asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="150px" DataField="Network" SortExpression="Network" HeaderText="Network"
            Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="150px" DataField="Product" SortExpression="Product" HeaderText="Product"
            Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="60px" DataField="Cost" SortExpression="Cost" HeaderText="Cost"
            Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" DataField="MobileNumber" SortExpression="MobileNumber"
            HeaderText="Mobile" Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="60px" DataField="PlanDescription" SortExpression="PlanDescription"
            HeaderText="Plan Description" Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="60px" DataField="PlanDuration" SortExpression="PlanDuration"
            HeaderText="Plan Duration" Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" DataField="Commission" SortExpression="Commission" HeaderText="Commission"
            Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" DataField="Rebate" SortExpression="Rebate" HeaderText="Rebate"
            Visible="true"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" DataField="MPP" SortExpression="MPP" HeaderText="MPP"
            Visible="true"></asp:BoundColumn>
    </Columns>
</asp:DataGrid>
<asp:HiddenField ID="hidSelectedID" runat="server" />
